package com.krahets88.doublepointer;

import org.junit.jupiter.api.Test;

public class Question167 {
    @Test
    public void test1(){
        Solution solve = new Solution();
        int numbers[] = new int[]{2,7,11,15};
        solve.twoSum(numbers,9);
    }

    class Solution {
        public int[] twoSum(int[] numbers, int target) {
            int i = 0, j = numbers.length - 1;
            while (numbers[i] + numbers[j] != target) {
                if (numbers[i] + numbers[j] > target) {
                    j--;
                } else if (numbers[i] + numbers[j] < target) {
                    i++;
                }
            }
            return new int[]{i+1, j+1};
        }
    }
}
